#include <iostream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <string.h>

using namespace std;

ifstream f("sarbato.txt");
ofstream g1("trecute.txt");
ofstream g2("viitoare.txt");

int luni[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

class data{
public:
	int zz, ll, aa;
	bool operator < (const data &other) const {
		return aa < other.aa || 
		aa == other.aa && ll < other.ll ||
		aa == other.aa && ll == other.ll && zz < other.zz;
	}
};

class sarbatori{
	data sarb[100];
	int nrSarb;
public:
	void citire(){
		f >> nrSarb;
		for(int i = 1; i <= nrSarb; i ++)
			f >> sarb[i].zz >> sarb[i].ll >> sarb[i].aa;
	}

	void afiseaza(){
		for(int i = 1; i <= nrSarb; i ++)
			if(sarb[i] < dataCurenta())
				g1 << sarb[i].zz << " " << sarb[i].ll << " " << sarb[i].aa << "\n";
			else
				g2 << sarb[i].zz << " " << sarb[i].ll << " " << sarb[i].aa << " ->" << diferenta(dataCurenta(), sarb[i]) << "\n";
	}
	
	data dataCurenta(){// ****** Eventual aici iei data curenta din sistem...Nu mai stiu sarbact cum era
		data d;
		d.zz = 15;
		d.ll = 2;
		d.aa = 2011;

		return d;
	}

	int diferenta(data a, data b){
		if(b < a)
			swap(a, b);
		if(a.aa == b.aa){
			if(a.ll == b.ll)
				return b.zz - a.zz;
			int dif = 0;
			dif = luni[a.ll] - a.zz;
			dif += b.zz;
			for(int i = a.ll + 1; i < b.ll; i ++)
				dif += luni[i];

			return dif;
		}
		int sum = 0;
		for(int i = 1; i <= 12; i ++)
			sum += luni[i];

		int dif = luni[a.ll] - a.zz;
		for(int i = a.ll + 1; i <= 12; i ++)
			dif += luni[i];
		dif += b.zz;
		for(int i = 1; i < b.ll; i ++)
			dif += luni[i];

		dif += max(b.aa - a.aa - 1, 0) * sum;

		return dif;
	}
};

int main(){
	sarbatori s;
	s.citire();
	s.afiseaza();

	return 0;
}